//
//  YHRequest+Config.m
//  YHNetwork
//
//  Created by 000 on 2021/12/26.
//

#import "YHRequest+Config.h"

@implementation YHRequest (Config)

- (YHRequest<id> *(^)(Class responseClass))responseClassRegister{
    YHRequest *(^block)(Class responseClass) = ^YHRequest *(Class responseClass) {
        self.config.responseClass = responseClass;
        return self;
    };
    return block;
}

- (YHRequest<id> *)configure:(void(^)(YHRequest * request, YHRequestConfig * config))configBlock{
    if(configBlock){
        configBlock(self,self.config);
    }
    return self;
}

- (YHRequest<id> *(^)(YTKRequestMethod method))method{
    YHRequest *(^block)(YTKRequestMethod method) = ^YHRequest *(YTKRequestMethod method) {
        self.config.method = method;
        return self;
    };
    return block;
}

- (YHRequest<id> *(^)(void))GET{
    YHRequest *(^block)(void) = ^YHRequest *(void) {
        self.config.method = YTKRequestMethodGET;
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(void))POST{
    YHRequest *(^block)(void) = ^YHRequest *(void) {
        self.config.method = YTKRequestMethodPOST;
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(void))PUT{
    YHRequest *(^block)(void) = ^YHRequest *(void) {
        self.config.method = YTKRequestMethodPUT;
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(void))DELETE{
    YHRequest *(^block)(void) = ^YHRequest *(void) {
        self.config.method = YTKRequestMethodDELETE;
        return self;
    };
    return block;
}

/// 请求失败重试次数
- (YHRequest<id> *(^)(NSInteger retryTimes))retryTimes{
    YHRequest *(^block)(NSInteger retryTimes) = ^YHRequest *(NSInteger retryTimes) {
        self.config.retryTimes = MAX(0, retryTimes);
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(NSInteger retryTimeInterval))retryTimeInterval{
    YHRequest *(^block)(NSInteger retryTimeInterval) = ^YHRequest *(NSInteger retryTimeInterval) {
        self.config.retryDelayInterval = MAX(0, retryTimeInterval);
        return self;
    };
    return block;
}

- (YHRequest<id> *(^)(NSString * pathurl))pathurl{
    YHRequest *(^block)(NSString * pathurl) = ^YHRequest *(NSString * pathurl) {
        self.config.pathURL = pathurl;
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(NSString * baseurl))baseurl{
    YHRequest *(^block)(NSString * baseurl) = ^YHRequest *(NSString * baseurl) {
        self.config.baseURL = baseurl;
        return self;
    };
    return block;
}
- (YHRequest<id> *(^)(NSString * fullurl))fullurl{
    YHRequest *(^block)(NSString * fullurl) = ^YHRequest *(NSString * fullurl) {
        self.config.baseURL = fullurl;
        self.config.pathURL = @"";
        return self;
    };
    return block;
}


@end
